package com.unionx.unionxuf.service;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.unionx.unionxuf.entity.CrDTD;
import com.unionx.unionxuf.entity.ReceivepayManger;
import com.unionx.unionxuf.entity.RmDTD;
import com.unionx.unionxuf.entity.tReceivepayManger;
import com.unionx.unionxuf.localdao.ReceivepayMangerMapper;

@Service("localReceivepayManagerService")
public class LocalReceivepayManagerServiceImpl implements LocalReceivepayManagerService {
	
	@Autowired(required=true)
	private ReceivepayMangerMapper rmm;
	
	public int insertReceivepay(ReceivepayManger c) {
		// TODO Auto-generated method stub
	
		int  i =  rmm.insert(c);
		
		return i;
	
	}

	@Override
	public int insertRp(ReceivepayManger receivepayManger) {
		// TODO Auto-generated method stub
		return rmm.insert1(receivepayManger);
	}

	@Override
	public Object delReceivepay(ReceivepayManger r) {
		// TODO Auto-generated method stub
		Map<String,Object> map = new HashMap<String,Object>();
		
		int  i  =  rmm.delRecivepay(r);
		map.put("status", i);
		return map;
	}

	@Override
	public Object findType(ReceivepayManger r) {
		// TODO Auto-generated method stub
		Map<String,Object> map = new HashMap<String,Object>();
		List<String>  list = rmm.finType(r);
		List<ReceivepayManger> rlist = new ArrayList<ReceivepayManger>();
		for(int i=0;i<list.size();i++){
			ReceivepayManger rm = new ReceivepayManger();
			rm.setCorp(list.get(i));
			rlist.add(rm);	
		}
		
		map.put("data", rlist);
		return map;
	}

	@Override
	public int updatebyls(ReceivepayManger receivepayManger) {
		// TODO Auto-generated method stub
		return rmm.updatebyls(receivepayManger);
	}

	@Override
	public ReceivepayManger selectby(int type, String string) {
		// TODO Auto-generated method stub
		ReceivepayManger r = new ReceivepayManger();
		
		r.setType(type);
		r.setCorp(string);
		return rmm.selectby(r);
	}
	
	@Override
	public RmDTD selectby2(int type, String string) {
		// TODO Auto-generated method stub
		
		return  rmm.selectby2(type,string);
	
	}

	@Override
	public Object selectrm(String cropid) {
		// TODO Auto-generated method stub
		List<ReceivepayManger> list = rmm.selectrm(cropid);
		List<tReceivepayManger> trlist = new ArrayList<tReceivepayManger>();
		
		for(int i=0;i<list.size();i++){
			ReceivepayManger r=  list.get(i);
			tReceivepayManger tr = new tReceivepayManger();
			
			tr.setId(r.getId());
			if(r.getType()==1){
				tr.setType("应收");
			}
			if(r.getType()==0){
				tr.setType("应付");
			}
			tr.setSubjectcode(r.getSubjectcode());
			tr.setSubjectname(r.getSubjectname());
			tr.setCorp(r.getCorp());
			tr.setAmount(r.getAmount());
			tr.setCorpid(r.getCorpid());
			tr.setIsno(r.getIsno());
			tr.setRemark(r.getRemark());
			tr.setZhuangtai(r.getZhuangtai());
			trlist.add(tr);
		}
		return trlist;
	}

	@Override
	public int updateRp(ReceivepayManger receivepayManger) {
		// TODO Auto-generated method stub
		return rmm.updateByPrimaryKey(receivepayManger);
	}


		
}
